// pages/person/setup/restpwd/restpwd.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userName: '胡兴',
        index: 0,
        array: [{
            name: '手机号码',
            u_type: 'mobile'
        }, {
            name: '电子邮箱',
            u_type: 'email'
        }],
        hidden: true,
        send: false,
        alreadySend: false,
        second: 60,
        disabled: true,
        buttonType: 'default',
        phoneNum: '',
        code: '',
        otherInfo: '',
        buttonmessage: '获取验证码',
        disabled: false,
        loading: false

    },
    sendMessage: function () {
        this.timer()
        this.setData({
            disabled: true,
            buttonmessage: '',
            second: 59,
            hidden: false
        })
    },
    submit: function () {
        this.setData({
            loading: true
        })
    },
    timer: function () {
        let promise = new Promise((resolve, reject) => {
            let setTimer = setInterval(
                () => {
                    this.setData({
                        second: this.data.second - 1
                    })
                    if (this.data.second <= 0) {
                        this.setData({
                            second: 60,
                            alreadySend: false,
                            send: true,
                            buttonmessage: '获取验证码',
                            disabled: false
                        })
                        resolve(setTimer)
                    }
                }
                , 1000)
        })
        promise.then((setTimer) => {
            clearInterval(setTimer)
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },
    bindPickerChange: function (e) {
        this.setData({
            index: e.detail.value
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})